package cn.ppool.xmlmapper.builder.parse.worker;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.Getter;

import java.util.Date;
import java.util.Map;
import java.util.UUID;

@Data
public class WorkStatusRecord {
    private int queryIndex;         // 请求序号
    private String queryId;
    private String sql;
    private Map<String, Object> sqlVal;
    private Map<String, Object> allVal;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date beginQueryTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date endQueryTime;

    private Long queryTime;

    public WorkStatusRecord() {
        this.queryId = UUID.randomUUID().toString();
    }

    public void setEndQueryTime(Date endQueryTime) {
        this.endQueryTime = endQueryTime;
        if (beginQueryTime != null) {
            queryTime = endQueryTime.getTime() - beginQueryTime.getTime();
        }
    }

    //
    @JsonIgnore
    private Throwable error;
    private String errorStack;
    private String errorMessage;


}
